var reviewService = {};
reviewService.methods = {};

$(function(){
    // 商品符合度star
    reviewService.methods.productStarsScore();

    // 商品商家服务态度star
    reviewService.methods.sellerStarsScore();

    // 物流满意度star
    reviewService.methods.transportStarsScore();

    // 发表
    reviewService.methods.published();
})

// 商品符合度star
reviewService.methods.productStarsScore = function(){
    var starsPScoreLi = $(".shop-reviewService-product-stars li");
    reviewService.n = -1;
    for(var i=0; i < starsPScoreLi.length; i++){
        starsPScoreLi[i].index = i;
        starsPScoreLi[i].onmouseover=function(){
            reviewService.methods.starsPScore(this.index);
         }
         
         starsPScoreLi[i].onmouseout=function(){ 
            reviewService.methods.starsPScore(reviewService.n);
         }
         
         starsPScoreLi[i].onclick=function(){
            reviewService.n=this.index;
            $(".shop-reviewService-product-scoreNum").text((reviewService.n+1)*2 + "分");
        } 
    }
}
// 商品符合度点亮star
reviewService.methods.starsPScore = function(productNum){
    var starsProductScoreLi = $(".shop-reviewService-product-stars li");
    
    for(var j=0;j<starsProductScoreLi.length;j++){
        if(j<=productNum){
            starsProductScoreLi[j].className="shop-productStars-active";//给之前的所有星星点亮
        }else{
            starsProductScoreLi[j].className="";//让所有的都不亮
        }
    }

}


// 商品商家服务态度star
reviewService.methods.sellerStarsScore = function(){
    var starsSScoreLi = $(".shop-reviewService-seller-stars li");
    reviewService.y = -1;
    for(var i=0; i < starsSScoreLi.length; i++){
        starsSScoreLi[i].index = i;
        starsSScoreLi[i].onmouseover=function(){
            reviewService.methods.starsSScore(this.index);
         }
         
         starsSScoreLi[i].onmouseout=function(){ 
            reviewService.methods.starsSScore(reviewService.y);
         }
         
         starsSScoreLi[i].onclick=function(){
            reviewService.y=this.index;
            $(".shop-reviewService-seller-scoreNum").text((reviewService.y+1)*2 + "分");
        } 
    }
}
// 商品商家服务态度点亮star
reviewService.methods.starsSScore = function(sellerNum){
    var starsSellerScoreLi = $(".shop-reviewService-seller-stars li");
    
    for(var k=0;k<starsSellerScoreLi.length;k++){
        if(k<=sellerNum){
            starsSellerScoreLi[k].className="shop-sellerStars-active";//给之前的所有星星点亮
        }else{
            starsSellerScoreLi[k].className="";//让所有的都不亮
        }
    }

}


// 物流满意度star
reviewService.methods.transportStarsScore = function(){
    var starsTScoreLi = $(".shop-reviewService-transport-stars li");
    reviewService.b = -1;
    for(var i=0; i < starsTScoreLi.length; i++){
        starsTScoreLi[i].index = i;
        starsTScoreLi[i].onmouseover=function(){
            reviewService.methods.starsTScore(this.index);
         }
         
         starsTScoreLi[i].onmouseout=function(){ 
            reviewService.methods.starsTScore(reviewService.b);
         }
         
         starsTScoreLi[i].onclick=function(){
            reviewService.b=this.index;
            $(".shop-reviewService-transport-scoreNum").text((reviewService.b+1)*2 + "分");
        } 
    }
}
// 物流满意度点亮star
reviewService.methods.starsTScore = function(transportNum){
    var starsTransportScoreLi = $(".shop-reviewService-transport-stars li");
    for(var x = 0; x < starsTransportScoreLi.length; x++){
        if(x <= transportNum){
            starsTransportScoreLi[x].className="shop-transportStars-active";
        }else{
            starsTransportScoreLi[x].className="";
        }
    }

}


// 发表
reviewService.methods.published = function () {  
    $(".shop-reviewService-published").on("click",".shop-reviewService-published-btn", function () {
        var spanTips = "<span class='spanTips' style='color:#e64545; margin-left:12px;'>*必选</span>";
        if ($(".shop-reviewService-product-stars li").hasClass("shop-productStars-active")) {
            Message.Show("提示", "提交评价", true, true, 5, "sureCancle", reviewService.methods.publishedEmpty, reviewService.methods.publishedCancel);

        } else {
            if($(".shop-reviewService-product-score").find("span").hasClass("spanTips")){
                return;
            }
            $(".shop-reviewService-product-score").append(spanTips);
        }
    })

    $(".shop-reviewService-product-stars").on("click", function () {
        $(".shop-reviewService-product-score").find(".spanTips").remove();
    })
}
// 再次发表前清空(确定按钮)
reviewService.methods.publishedEmpty = function () {
    $(".shop-reviewService-product-stars li").removeClass("shop-productStars-active");
    $(".shop-reviewService-product-scoreNum").text("0分");
    reviewService.n = -1;
    $(".shop-reviewService-seller-stars li").removeClass("shop-sellerStars-active");
    $(".shop-reviewService-seller-scoreNum").text("0分");
    reviewService.y = -1;
    $(".shop-reviewService-transport-stars li").removeClass("shop-transportStars-active");
    $(".shop-reviewService-transport-scoreNum").text("0分");
    reviewService.b = -1;
    return true;

}
// (取消按钮)
reviewService.methods.publishedCancel = function () {
    return true;
}